//
//  ShuaWordDetailViewController.m
//  Learn
//
//  Created by apple on 2024/4/19.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "ShuaWordDetailViewController.h"
#import "ShuaWordRequest.h"

@interface ShuaWordDetailViewController ()

@property (nonatomic, strong) UIButton    * preBtn;

@property (nonatomic, strong) UIButton    * nextBtn;
@property (nonatomic, strong) UIButton    * voiceBtn;

@property (nonatomic, strong) UILabel    * wordLabel;
@property (nonatomic, strong) UILabel    * yinbiaoLabel;
@property (nonatomic, strong) UILabel    * expLabel;

@property (nonatomic, strong) UIImageView    * logoImg;

@property (nonatomic, strong) UIView    * tipView;
@property (nonatomic, strong) UILabel    * lijuLabel;
@property (nonatomic, strong) UILabel    * lijuEnLabel;
@property (nonatomic, strong) UILabel    * lijuZhLabel;

@property (nonatomic, strong) UIView    * lineView;
@property (nonatomic, strong) UIView    * tipView1;
@property (nonatomic, strong) UILabel    * genduLabel;
@property (nonatomic, strong) UILabel    * genduLabel2;
@property (nonatomic, strong) UIButton    * voiceBtn2;
@property (nonatomic, strong) UILabel    * yinbiaoLabel2;
@property (nonatomic, strong) UILabel    * scoreLabel;


/* <#描述#> */
@property (nonatomic, strong) ShuaWordModel    * model;
@end

@implementation ShuaWordDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
  
    self.title = @"单词详情";

    [self initUI];
    [self getRequestData];
}
- (void)initUI {
    [self.view addSubview:self.voiceBtn];
    [self.view addSubview:self.preBtn];
    [self.view addSubview:self.nextBtn];

    [self.view addSubview:self.wordLabel];
    [self.view addSubview:self.yinbiaoLabel];
    [self.view addSubview:self.expLabel];
    
    [self.view addSubview:self.logoImg];
    [self.view addSubview:self.tipView];
    [self.view addSubview:self.lijuLabel];
    [self.view addSubview:self.lijuEnLabel];
    [self.view addSubview:self.lijuZhLabel];
    
    [self.view addSubview:self.lineView];
    [self.view addSubview:self.tipView1];
    [self.view addSubview:self.genduLabel];
    [self.view addSubview:self.genduLabel2];
    [self.view addSubview:self.voiceBtn2];
    [self.view addSubview:self.yinbiaoLabel2];
    [self.view addSubview:self.scoreLabel];
}
//@property (nonatomic, strong) UIView    * lineView;
//@property (nonatomic, strong) UIView    * tipView1;
//@property (nonatomic, strong) UILabel    * genduLabel;
//@property (nonatomic, strong) UILabel    * genduLabel2;
//@property (nonatomic, strong) UIButton    * voiceBtn2;
//@property (nonatomic, strong) UILabel    * yinbiaoLabel2;
//@property (nonatomic, strong) UILabel    * scoreLabel;
- (UILabel *)scoreLabel {
    if(!_scoreLabel){
        _scoreLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 + self.voiceBtn2.right, 10 + self.wordLabel.bottom, 100, 25)];
        _scoreLabel.right = self.genduLabel2.right;
        _scoreLabel.centerY = self.voiceBtn2.centerY;
        _scoreLabel.text = @"0";
        _scoreLabel.textColor = UIColor.blackColor;
        _scoreLabel.font = PingFangMediumFont(16);
        _scoreLabel.textAlignment = NSTextAlignmentRight;
    }
    return _scoreLabel;
}

- (UILabel *)yinbiaoLabel2 {
    if(!_yinbiaoLabel2){
        _yinbiaoLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(10 + self.voiceBtn2.right, 10 + self.wordLabel.bottom, 100, 25)];
        _yinbiaoLabel2.centerY = self.voiceBtn2.centerY;
//        _yinbiaoLabel.text = @"[a'gau]";
        _yinbiaoLabel2.textColor = UIColor.blackColor;
        _yinbiaoLabel2.font = PingFangMediumFont(16);
        _yinbiaoLabel2.textAlignment = NSTextAlignmentLeft;
    }
    return _yinbiaoLabel2;
}
- (UIButton *)voiceBtn2 {
    if(!_voiceBtn2){
        _voiceBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        _voiceBtn2.frame = CGRectMake(self.tipView1.left, self.genduLabel.bottom + 15, 40, 40);
        
        [_voiceBtn2 setImage:[UIImage imageNamed:@"voiceIcon"] forState:UIControlStateNormal];
        [_voiceBtn2 addTarget:self action:@selector(voice2BtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _voiceBtn2;
}

- (UILabel *)genduLabel2 {
    if(!_genduLabel2){
        _genduLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(self.tipView1.right + 9, self.tipView1.top - 2, 100, 22)];
        _genduLabel2.centerY = self.genduLabel.centerY;
        _genduLabel2.right = SCREEN_W - 27;
        _genduLabel2.text = @"我的跟读";
        _genduLabel2.textColor = COLOR_NOT_SELECT;
        _genduLabel2.font = PingFangMediumFont(16);
        _genduLabel2.textAlignment = NSTextAlignmentRight;
    }
    return _genduLabel2;
}
- (UILabel *)genduLabel {
    if(!_genduLabel){
        _genduLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.tipView1.right + 9, self.tipView1.top - 2, 100, 22)];
        _genduLabel.text = @"我的跟读";
        _genduLabel.textColor = COLOR_NOT_SELECT;
        _genduLabel.font = PingFangMediumFont(16);
        _genduLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _genduLabel;
}
- (UIView *)tipView1 {
    if(!_tipView1){
        _tipView1 = [[UIView alloc]initWithFrame:CGRectMake(self.logoImg.left
                                                           , self.lineView.bottom + 19, 4, 14 )];
        
        _tipView1.backgroundColor = COLOR_TOPIC_SELECT;
    }
    return _tipView1;
}

- (UIView *)lineView {
    if(!_lineView){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 15 + self.lijuZhLabel.bottom, SCREEN_W, 0.5)];
        
        _lineView.backgroundColor = rgbHex(0xe5e5e5, 1);
    }
    return _lineView;
}

- (UILabel *)lijuZhLabel {
    if(!_lijuZhLabel){
        _lijuZhLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, self.lijuEnLabel.bottom + 5, SCREEN_W - 56, 22)];
//        _lijuZhLabel.text = @"我是两天前来这儿的";
        _lijuZhLabel.textColor = COLOR_BLACK;
        _lijuZhLabel.font = PingFangMediumFont(16);
        _lijuZhLabel.textAlignment = NSTextAlignmentLeft;
        _lijuZhLabel.hidden = YES;
    }
    return _lijuZhLabel;
}
- (UILabel *)lijuEnLabel {
    if(!_lijuEnLabel){
        _lijuEnLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, self.lijuLabel.bottom + 10, SCREEN_W - 56, 22)];
//        _lijuEnLabel.text = @"I came here two days ago..";
        _lijuEnLabel.textColor = COLOR_BLACK;
        _lijuEnLabel.font = PingFangMediumFont(16);
        _lijuEnLabel.textAlignment = NSTextAlignmentLeft;
        _lijuEnLabel.hidden = YES;
    }
    return _lijuEnLabel;
}
- (UILabel *)lijuLabel {
    if(!_lijuLabel){
        _lijuLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.tipView.right + 9, self.tipView.top - 2, 100, 22)];
        _lijuLabel.text = @"例句";
        _lijuLabel.textColor = COLOR_NOT_SELECT;
        _lijuLabel.font = PingFangMediumFont(16);
        _lijuLabel.textAlignment = NSTextAlignmentLeft;
        _lijuLabel.hidden = YES;
    }
    return _lijuLabel;
}
- (UIView *)tipView {
    if(!_tipView){
        _tipView = [[UIView alloc]initWithFrame:CGRectMake(self.logoImg.left
                                                           , self.logoImg.bottom + 19, 4, 14 )];
        
        _tipView.backgroundColor = COLOR_TOPIC_SELECT;
        _tipView.hidden = YES;
    }
    return _tipView;
}

- (UIImageView *)logoImg {
    if(!_logoImg){
        _logoImg = [[UIImageView alloc]initWithFrame:CGRectMake(28, 30 + self.expLabel.bottom, SCREEN_W - 56,0.56 *(SCREEN_W - 56))];
        _logoImg.contentMode = UIViewContentModeScaleAspectFill;
        [_logoImg js_setRoundedCorners:UIRectCornerAllCorners radii:10];
//        _logoImg.image = [UIImage imageNamed:@"planBg"];
    }
    return _logoImg;
}

- (UILabel *)expLabel {
    if(!_expLabel){
        _expLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 15 + self.yinbiaoLabel.bottom, SCREEN_W, 25)];
//        _expLabel.text = @"adv.以前";
        _expLabel.textColor = COLOR_NOT_SELECT;
        _expLabel.font = PingFangMediumFont(18);
        _expLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _expLabel;
}
- (UILabel *)yinbiaoLabel {
    if(!_yinbiaoLabel){
        _yinbiaoLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10 + self.wordLabel.bottom, SCREEN_W, 25)];
//        _yinbiaoLabel.text = @"[a'gau]";
        _yinbiaoLabel.textColor = COLOR_NOT_SELECT;
        _yinbiaoLabel.font = PingFangMediumFont(18);
        _yinbiaoLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _yinbiaoLabel;
}
- (UILabel *)wordLabel {
    if(!_wordLabel){
        _wordLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30 + NavigationBarHeight, SCREEN_W, 45)];
//        _wordLabel.text = @"ago";
        _wordLabel.textColor = COLOR_BLACK;
        _wordLabel.font = PingFangMediumFont(32);
        _wordLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _wordLabel;
}

- (UIButton *)voiceBtn {
    if(!_voiceBtn){
        _voiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _voiceBtn.frame = CGRectMake(SCREEN_W - 40, NavigationBarHeight, 40, 40);
        
        [_voiceBtn setImage:[UIImage imageNamed:@"voiceIcon"] forState:UIControlStateNormal];
        [_voiceBtn addTarget:self action:@selector(voiceBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _voiceBtn;
}


- (UIButton *)preBtn {
    if(!_preBtn){
        _preBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _preBtn.frame = CGRectMake(10, SCREEN_H - SafeAreaBottomHeight - 55, SCREEN_W/2 - 35/2, 45);
        _preBtn.backgroundColor = UIColor.whiteColor;
        [_preBtn setTitle:@"下一个" forState:UIControlStateNormal];

        
        [_preBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
        _preBtn.titleLabel.font  = PingFangMediumFont(18);
      
        [_preBtn js_setRoundedCorners:UIRectCornerAllCorners radii:22.5 borderColor:UIColor.blackColor width:1];
        [_preBtn addTarget:self action:@selector(preBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _preBtn;
}
- (UIButton *)nextBtn {
    if(!_nextBtn){
        _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _nextBtn.frame = CGRectMake(15 + self.preBtn.right, SCREEN_H - SafeAreaBottomHeight - 55, self.preBtn.width, 45);
        [_nextBtn setTitle:@"下一个" forState:UIControlStateNormal];

        
        [_nextBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        _nextBtn.titleLabel.font  = PingFangMediumFont(18);
        _nextBtn.az_colors = @[(__bridge id)rgbHex(0x02A1F9, 1).CGColor,(__bridge id)rgbHex(0x29F19C,1).CGColor];
        _nextBtn.az_startPoint = CGPointMake(0, 0.5);
        _nextBtn.az_endPoint = CGPointMake(1, 0.5);
        [_nextBtn js_setRoundedCorners:UIRectCornerAllCorners radii:22.5];
        [_nextBtn addTarget:self action:@selector(nextBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;
}

#pragma mark   底部按钮点击
- (void)preBtnClicked:(UIButton *)sender {
    if (self.index == 0) {
        [SVProgressHUD showImage:nil status:@"已是第一个"];
        return;
    }
    self.index --;
    ShuaWordModel *model = self.dataArray[self.index];
    self.wordId = model.ID;
    [self getRequestData];
}
- (void)nextBtnClicked:(UIButton *)sender {
    if (self.index == self.dataArray.count - 1) {
        [SVProgressHUD showImage:nil status:@"已是最后一个"];
        return;
    }
    self.index ++;
    ShuaWordModel *model = self.dataArray[self.index];
    self.wordId = model.ID;
    [self getRequestData];
}


#pragma mark   播放
- (void)voiceBtnClicked:(UIButton *)sender {
    
}
- (void)voice2BtnClicked:(UIButton *)sender {
    
}

- (void)getRequestData{
    WS(WeakSelf)
    [ShuaWordRequest request_getWordInfoWithId:self.wordId reslut:^(ShuaWordModel * _Nonnull model, BOOL isRequest) {
        if (isRequest) {
            [WeakSelf updateUIWithModel:model];
        }
    }];
}
- (void)updateUIWithModel:(ShuaWordModel*)model {
    self.model = model;
    self.wordLabel.text = model.words_detail.words;
    self.yinbiaoLabel.text = [NSString stringWithFormat:@"[%@]",model.words_detail.symbol];
    self.expLabel.text = model.words_detail.pretations;
    [self.logoImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.words_detail.wordPic]]];
    
    self.tipView.hidden = self.lijuLabel.hidden = self.lijuEnLabel.hidden = self.lijuZhLabel.hidden = YES;
    
    self.yinbiaoLabel2.text = [NSString stringWithFormat:@"[%@]",model.words_detail.symbol];
    self.scoreLabel.text = [NSString stringWithFormat:@"%@",model.score];

}
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
@end
